home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 2 / Amiga Tools 2.iso / net / parnet-3.2 / extras / parpc / amigafiles / test / get.c < prev    next >
C/C++ Source or Header  |  1995-03-09  |  2KB  |  84 lines

  1. /*
  2.  *  GET.C
  3.  *
  4.  *  GET port
  5.  *
  6.  *  receives data from port and prints results, massive receive w/ multiple
  7.  *  requests queued.
  8.  */
  9.  
  10. #include "defs.h"
  11.  
  12. #define REQS    8
  13.  
  14. typedef struct IORequest IOR;
  15.  
  16. Iob iob[REQS];
  17. char Buf[8192];
  18.  
  19. int
  20. brk(void)
  21. {
  22.     return(0);
  23. }
  24.  
  25. void
  26. main(ac, av)
  27. int ac;
  28. char *av[];
  29. {
  30.     PORT *port = CreatePort(NULL, 0);
  31.     long bytes = 0;
  32.     short i;
  33.     long j;
  34.  
  35.     onbreak(brk);
  36.     iob[0].io_Message.mn_ReplyPort = port;
  37.     iob[0].io_Port = atoi(av[1]);
  38.     iob[0].io_Flags= PRO_DGRAM;
  39.  
  40.     if (OpenDevice("parnet.device", 0, (IOR *)&iob[0], 0)) {
  41.     printf("Unable to open parnet.device, error %d %d\n", iob[0].io_Error, iob[0].io_Actual);
  42.     exit(1);
  43.     }
  44.     printf("Device $%08lx Unit $%08lx\n", iob[0].io_Device, iob[0].io_Unit);
  45.  
  46.     iob[0].io_Command = CMD_READ;
  47.     iob[0].io_Data    = (APTR)Buf;
  48.     iob[0].io_Length  = sizeof(Buf);
  49.  
  50.     for (i = 1; i < REQS; ++i)
  51.     iob[i] = iob[0];
  52.     for (i = 0; i < REQS; ++i)
  53.     SendIO((IOR *)&iob[i]);
  54.  
  55.     j = 0;
  56.  
  57.     for (;;) {
  58.     long mask;
  59.     Iob *io;
  60.  
  61.     mask = Wait(SIGBREAKF_CTRL_E | (1 << port->mp_SigBit));
  62.  
  63.     if (mask & SIGBREAKF_CTRL_E)
  64.         break;
  65.  
  66.     while (io = (Iob *)GetMsg(port)) {
  67.         bytes += io->io_Actual;
  68.         SendIO((IOR *)io);
  69.         ++j;
  70.         if ((j & 15) == 0)
  71.         printf("Got %3ld %dK\n", j, bytes >> 10);
  72.     }
  73.     }
  74.     printf("Aborting...\n");
  75.     for (i = 0; i < REQS; ++i) {
  76.     AbortIO((IOR *)&iob[i]);
  77.     WaitIO((IOR *)&iob[i]);
  78.     }
  79.     printf("Closing...\n");
  80.     CloseDevice((IOR *)&iob[0]);
  81.     DeletePort(port);
  82. }
  83.  
  84.